﻿#include "Teacher.h"

// 默认构造
Teacher::Teacher()
{
}

Teacher::Teacher(int id, string name, string pwd)
{
	this->m_Id = id;
	this->m_Name = name;
	this->m_Pwd = pwd;
}
// 有参构造
Teacher::Teacher(int id, string name, string pwd, OrderFile* o, ComputerRoomFile* c)
{
	this->m_Id = id;
	this->m_Name = name;
	this->m_Pwd = pwd;
	this->m_orderFile = o;
	this->m_ComputerRoomFile = c;
	this->m_mReviewOrder.clear();
	this->m_orderFile->getReviewOrder(this->m_mReviewOrder);
}

// 默认析构
Teacher::~Teacher()
{
}

// 老师菜单界面
void Teacher::operMenu()
{
	cout << "欢迎教师：" << this->m_Name << "登录！" << endl;
	cout << "\t\t ----------------------------------\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          1.查看所有预约          |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          2.审核预约              |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          0.注销登录              |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t ----------------------------------\n";
	cout << "请选择您的操作： " << endl;
}

// 展示所有预约
void Teacher::showAllOrder()
{
	this->m_orderFile->showAllOrder();
	system("pause");
	system("cls");
}

// 审核预约
void Teacher::reviewOrder()
{
	if (this->m_mReviewOrder.size() == 0)
	{
		cout << "无预约信息！" << endl;
		system("pause");
		system("cls");
		return;
	}
	vector<int> vIndex;// 记录可以审核的记录的索引号
	cout << "待审核的预约记录如下：" << endl;
	for (map<int, Order>::iterator it = this->m_mReviewOrder.begin(); it != this->m_mReviewOrder.end(); it++)
	{
		cout << "第" << vIndex.size() + 1 << "条预约记录：" << endl;
		cout << "学号：" << it->second.m_StuId << " "
			<< "用户名：" << it->second.m_StuName << " "
			<< "时间：" << DATE[it->second.m_Date]
			<< INTERVAL[it->second.m_Interval] << " "
			<< "地点：" << it->second.m_RoomId << "号机房 "
			<< "状态：" << STATUS[it->second.m_Status] << endl;
		cout << endl;
		vIndex.push_back(it->first);
	}
	int index;
	bool isPassed = false;
	cout << "请输入要审核的记录（0-返回）：" << endl;
	while (true)
	{
		cin >> index;
		if (index == 0)
		{
			break;
		}
		else if (index > 0 && index <= (int)vIndex.size())
		{
			cout << "请输入审核结果：" << endl;
			cout << "1-通过 2-不通过" << endl;
			int select;
			cin >> select;
			if (select == 1)
			{
				isPassed = true;
			}
			this->m_orderFile->review(vIndex[index - 1], isPassed);
			if (!isPassed)
			{
				// todo 机房可预约数量+1
				//cout << this->m_mReviewOrder[vIndex[index - 1]].m_RoomId << "号机房喜加一" << endl;
				this->m_ComputerRoomFile
					->updateCurrentNumById(this->m_mReviewOrder[vIndex[index - 1]].m_RoomId, 1);
			}
			cout << "审核完毕！" << endl;
			// 数据更新
			this->m_mReviewOrder.clear();
			this->m_orderFile->getReviewOrder(this->m_mReviewOrder);
			break;
		}
		else
		{
			cout << "输入有误，请重新输入：" << endl;
		}
	}

	system("pause");
	system("cls");
}